package com.api.utils;

import com.mybatisflex.core.paginate.Page;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @Author: yangsf
 * @CreateDate: 2024/10/22
 */
public class ParamsUtils {


    public static Page toPage(Map<String,Object> params){
        int pageNum = 1;
        int pageSize = 10;
        if(params.containsKey("pageNumber") && null != params.get("pageNumber") && !StringUtils.isEmpty(params.get("pageNum"))){
            int pn = Integer.parseInt(params.get("pageNumber").toString());
            if(pn > 0){
                pageNum = pn;
            }
        }
        if(params.containsKey("pageSize") && null != params.get("pageSize") && !StringUtils.isEmpty(params.get("pageSize"))){
            int ps = Integer.parseInt(params.get("pageSize").toString());
            if(ps > 0){
                pageSize = ps;
            }
        }
        return new Page<>(pageNum,pageSize);
    }

}
